package main
import "fmt"

type Books struct {
    title string
    author string
    subject string
    book_id int
}

func main() {
    // 创建一个新的结构体
    fmt.Println(Books{"Go语言", "www.runoob.com", "Go语言教程", 100001})

    // 也可以用key => value格式
    fmt.Println(Books{title: "Go语言", author: "www.runoob.com", subject: "Go语言教程", book_id: 100001})

    // 忽略的字段为0或空
    fmt.Println(Books{title: "Go语言", author: "www.runoob.com"})

    var Book1 Books
    var Book2 Books

    // Book1 描述
    Book1.title = "Go语言"
    Book1.author = "www.runoob.com"
    Book1.subject = "Go语言教程"
    Book1.book_id = 100001

    // Book2 描述
    Book2.title = "Python语言"
    Book2.author = "www.runoob.com"
    Book2.subject = "Python语言教程"
    Book2.book_id = 100002

    // 打印Book1 信息
    fmt.Printf("Book1 title: %s\n", Book1.title)
    fmt.Printf("Book1 auhtor: %s\n", Book1.author)
    fmt.Printf("Book1 subject: %s\n", Book1.subject)
    fmt.Printf("Book1 book_id: %d\n", Book1.book_id)
   
    // 打印Book2 信息
    fmt.Printf("Book2 title: %s\n", Book2.title)
    fmt.Printf("Book2 auhtor: %s\n", Book2.author)
    fmt.Printf("Book2 subject: %s\n", Book2.subject)
    fmt.Printf("Book2 book_id: %d\n", Book2.book_id)

    printBook(Book1)
    printBook(Book2)

    printBookPointer(&Book1)
    printBookPointer(&Book2)
}

func printBook(book Books) {
    fmt.Printf("book title: %s\n", book.title)
    fmt.Printf("book auhtor: %s\n", book.author)
    fmt.Printf("book subject: %s\n", book.subject)
    fmt.Printf("book book_id: %d\n", book.book_id)
}

func printBookPointer(book *Books) {
    fmt.Printf("book title: %s\n", book.title)
    fmt.Printf("book auhtor: %s\n", book.author)
    fmt.Printf("book subject: %s\n", book.subject)
    fmt.Printf("book book_id: %d\n", book.book_id)
}
